<template>
	<view>
		<my-search @handleClick="gotoSearch()"></my-search>
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="3000"
				:duration="1000">
				<swiper-item v-for="(item, i) in swiperList" :key="i">	
					<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">	
						<image :src="item.image_src" :mode="widthFix"></image>
					</navigator>
				</swiper-item>
			</swiper>
		</view>
		<view class="nav-row" >
			<view  v-for="(item,i) in navigatorList" :key="i" @click="navClickHandler(item)">
				<image :src="item.image_src" :mode="heightFix" class="nav-image"></image>
			</view>
		</view>	
		<view class="floor-row" v-for="(item,i) in floorList" :key="i">
			<!-- 楼层标题 -->
			<view>
				<image :src="item.floor_title.image_src" :mode="heightFix" class="floor-title-img"></image>
			</view>
			<!-- 楼层图片 -->
			<view class="floor-product">
				<!-- 左侧大图片 -->
				<navigator class="floor-product-one" :url="item.product_list[0].url">
					<image :src="item.product_list[0].image_src"  :style="{width: item.product_list[0].image_width + 'rpx'}"  mode="widthFix"></image>
				</navigator>
				<!-- 右侧图片 -->
				<view class="floor-product-right">
					<navigator :url="item1.url" class="floor-product-two" v-for="(item1,j) in item.product_list" v-if="j !== 0">
						<image :src="item1.image_src"  :style="{width: item1.image_width + 'rpx'}"  mode="widthFix"></image>
					</navigator>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
import { toast } from '../../utils/common';
	export default {
		data() {
			return {
				swiperList: [],
				navigatorList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList(){
				const { data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status !== 200){
					return toast("请求数据失败！")
				}
				this.swiperList = res.message
			},
			async getNavList(){
				const { data:res } = await uni.$http.get('/api/public/v1/home/catitems')
				if(res.meta.status !== 200){
					return toast("请求数据失败！")
				}
				this.navigatorList = res.message
 			},
			async getFloorList(){
				const { data:res } = await uni.$http.get('/api/public/v1/home/floordata')
				if(res.meta.status !== 200){
					return toast("请求数据失败！")
				}
				res.message.forEach(floor => {
					floor.product_list.forEach(item =>{
						item.url = '/subpkg/goods_list/goods_list?' + item.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
			},
			navClickHandler(item){
				if(item.name == '分类'){
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	.uni-margin-wrap {
			width: 690rpx;
			width: 100%;
	}
	.swiper {
		height: 300rpx;
		.swiper-item {
				display: block;
				height: 300rpx;
				line-height: 300rpx;
				text-align: center;
				image{
					width: 100%;
					height: 100%;
				}
		}
	}	
	.uni-bg-red{
		background-color: aquamarine;
	}

	.nav-row{
		margin: 15rpx 0;
		height: 150rpx;
		display: flex;	
		justify-content: space-around;
		
		.nav-image{
			width: 128rpx;
			height: 140rpx;
		}
	}
	.input-view {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		// width: 500rpx;
		flex: 1;
		background-color: #f8f8f8;
		height: 30px;
		border-radius: 15px;
		padding: 0 15px;
		flex-wrap: nowrap;
		margin: 7px 0;
		line-height: 30rpx;
	}
	.input-uni-icon {
		line-height: 30px;
	}
	.nav-bar-input {
		height: 30px;
		line-height: 30px;
		/* #ifdef APP-PLUS-NVUE */
		width: 370rpx;
		/* #endif */
		padding: 0 5px;
		font-size: 12px;
		background-color: #f8f8f8;
	}
	.floor-row {
		justify-content: space-around;
		
		.floor-title-img {
			width: 100%;
			height: 60rpx;
		}
		
		.floor-product {
			display: flex;
			padding-left: 10rpx;	
		
			.floor-product-right{
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}
			
		}
	}
	
</style>
